#ifndef __MM_H
#define __MM_H

#include <stdio.h>
#include <stdint.h>
#include <unistd.h>

//XXX 64M
#define MAX_SIZE		(0xfffful) 
#define PROCESS_NAME_LEN	(100)

struct free_section {
	uint32_t size;
	uint32_t start_addr;
	uint32_t end_addr;
	struct free_section *next;
};

struct allocate_section {
	uint32_t pid;
	uint32_t size;
	uint32_t start_addr;
	uint32_t end_addr;
	char process_name[PROCESS_NAME_LEN];
	struct allocate_section *next;
};

struct mm_ctrl {
	uint32_t max_size;
	uint32_t free_size;
	uint32_t allocate_size;
	uint32_t start_addr;
	uint32_t end_addr;
	uint32_t process_nums;
	struct free_section *free_head;
	struct allocate_section *allocate_head;
	struct free_section *cur_free_handler;
	struct allocate_section *cur_allocate_handler;
};

struct mm_ctrl *mm_init(uint32_t, uint32_t);
int new_process(struct mm_ctrl *ctrl, uint32_t size, const char *process_name);
int des_process(struct mm_ctrl *ctrl, uint32_t size, const char *process_name);
int mm_free(struct mm_ctrl *, uint32_t, uint32_t, const char *);
int mm_allocate(struct mm_ctrl *, uint32_t, uint32_t, const char *);
#endif
